package com.sqstudio.llk.command
{
	
	import com.sqstudio.llk.command.event.GameEvent;
	import com.sqstudio.llk.model.GameModel;
	import com.sqstudio.llk.view.ItemMediator;
	import com.sqstudio.llk.view.ItemView;
	
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	
	import org.robotlegs.mvcs.Command;
	/**
	 *路径判断命令 
	 * @author Nestor
	 * 
	 */	
	public class PathLogicCommand extends Command
	{
		
		[Inject]
		public var model:GameModel;
		
		[Inject]
		public var event:GameEvent;

		
		public function PathLogicCommand()
		{
			super();
		}
		
		override public function execute():void
		{
			var item:ItemMediator  = (event.crtTarget as ItemMediator);
			if(item.item.itemVo.type == 0) return;
			model.item1 = model.item1;
			model.item2 = model.item2;
			if(model.item1 == item){
				model.item1.changeFilters();
				model.item1 = null;
				return;
			}
			if(model.item2 == item){
				model.item2.changeFilters();
				model.item2 = null;
				return;
			}
			if(model.item1 == null){
				model.item1 = item;
				model.item1.changeFilters(true);
			}else if(model.item2 == null){
				model.item2 = item;
				model.item2.changeFilters(true);
			}else{
				model.item1.changeFilters();
				model.item2.changeFilters(); 
				model.item2 = null;
				model.item1 = item;
				model.item1.changeFilters(true);
			}
			checkPath();
		}
		
		private function checkPath():void{
			if(model.item1 == null || model.item2 == null) return;
			if(model.item1.item.itemVo.type != model.item2.item.itemVo.type) return;
			if(PathLogic.checkPoint(model.item1.item.itemVo.p,model.item2.item.itemVo.p)){
				trace("OK!");
				model.item1.changeFilters();
				model.item2.changeFilters();
				model.item1.changeType();
				model.item2.changeType();
				model.item1 = model.item2 = null;
			}else{
				trace("NO!");
			}
			
		}
		
	}
}